package com.tangcl.module_commom.base

import android.os.Handler
import android.os.Looper
import java.lang.ref.WeakReference

/**
 * Created by TCL on 2021/10/14
 *
 * description:内部类弱引用Handler基类
 *
 * 记得持有 Activity 尽量采用静态内部类 + 弱引用的写法，另外在 Activity 销毁的时候及时地终止 Thread 或清空 Message。
 *  thread.interrupt()
 *  handler.removeCallbacksAndMessages(null)
 */
open class BaseWeakReferenceHandler<T>(looper: Looper?, referencedObject: T) : Handler(looper!!) {
    private val mReference: WeakReference<T> = WeakReference(referencedObject)

    protected val referencedObject: T?
        get() = mReference.get()

}